import time

import allure

from .base import Base

from selenium.webdriver.common.by import By


class Contact(Base):    # 通讯录页
    __ADD_MEMBER = (By.CSS_SELECTOR, "div.js_has_member > div:nth-child(1) > a")   # 添加成员按钮
    __ADD_MEMBER_NAME = (By.ID, "username")     # 添加成员的名字
    __ADD_MEMBER_ACCTID = (By.ID, "memberAdd_acctid")   # 添加成员的唯一标识符
    __ADD_MEMBER_PHONE = (By.ID, "memberAdd_phone")     # 添加成员的手机号
    __ADD_MEMBER_SAVE = (By.LINK_TEXT, "保存")    # 保存按钮

    def add_member(self, member_name, member_phone_number):
        with allure.step("添加成员"):
            from .page_jumps import PageJumps   # 内部导入,要不然系统会重复导入,无限循环,报错
            time.sleep(1)
            self.find_click(self.__ADD_MEMBER)    # 添加成员
            self.find_key(self.__ADD_MEMBER_NAME, member_name)  # 添加成员的名字
            self.find_key(self.__ADD_MEMBER_ACCTID, member_phone_number)    # 添加成员的唯一标识符
            self.find_key(self.__ADD_MEMBER_PHONE, member_phone_number)     # 添加成员的手机号
            self.images_log("input", "信息输入")    # 截图
            self.finds_click(self.__ADD_MEMBER_SAVE, 1)     # 保存
        return PageJumps(self.driver)   # 添加完毕之后,返回到页面中获取信息
